package com.rede.didiok.admin.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import com.rede.didiok.admin.service.LinkService;
import com.rede.didiok.common.dto.admin.LinkDto;
import com.rede.didiok.common.utils.R;

// import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 友情链接表
 *
 * @author Rede
 * @email didiok@foxmail.com
 * @date 2023-08-07 18:21:17
 */
@RestController
@RequestMapping("admin/feign/link")
public class LinkController {
    @Autowired
    private LinkService linkService;

    /**
     * 通过 ids 查询友链
     */
    @PostMapping(value = "/lisLinktByUids")
    R lisLinktByUids(@RequestBody List<String> linkUids){
        return R.ok().setData(linkService.listByIds(linkUids));
    }


    /**
     * 根据用户uid和友链名获取一条连接
     * @param userUid
     * @param title
     * @return
     */
    @GetMapping("/getLinkByUserUidAndTitle")
    R getLinkByUserUidAndTitle(@RequestParam("userUid") String userUid, @RequestParam("title")String title){
        return R.ok().setData(linkService.getLinkByUserUidAndTitle(userUid,title));
    }

    /**
     * 保存一条友链
     * @param linkDto
     * @return
     */
    @RequestMapping(value = "/admin/feign/link/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = "application/json;charset=UTF-8")
    R addOneLink(@RequestBody LinkDto linkDto){
        return R.ok().setData(linkService.addOneLink(linkDto));
    }

    /**
     * 通过页大小获取友链列表
     *
     * @param size
     */
    @GetMapping("/getListByPageSize")
    R getLinkListByPageSize(Integer size){
        return R.ok().setData(linkService.getListByPageSize(size));
    }
}
